package com.oig.sys.base.dao;

import com.oig.sys.base.entity.TbEnum;
import com.oig.sys.base.vo.EnumVo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
@author wuxl
*/
public interface ITbEnumDao extends JpaRepository<TbEnum, Integer> {

	TbEnum getTbEnumById(Integer id);

	@Query("from TbEnum e where e.dictCode=:dictCode")
	TbEnum getByDictCode(@Param("dictCode") String dictCode);

	@Query("from TbEnum e where e.status=:status")
	List<TbEnum> findAllByStatus(@Param("status") String status);


	@Query("select new com.oig.sys.base.vo.EnumVo(e.id,e.dictCode,e.dictName,e.status, e.modifyFlag, e.remark," +
			"e.parentDictCode, e.createUserName, e.createTime, e.lastUpdateName, e.lastUpdateTime)" +
			"from TbEnum e where e.dictCode like CONCAT('%',:searchKey,'%') or e.dictName like CONCAT('%',:searchKey,'%')")
	List<EnumVo> findAllByCodeOrName(@Param("searchKey") String searchKey);
}
